package cn.com.scitc.licenseplateback.dao;

import cn.com.scitc.licenseplateback.model.BookingWarehousingEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface BookingWarehousingDao extends CrudRepository<BookingWarehousingEntity, String> {

    /**
     * 根据订单编号进行预约查询
     * @param tradeNo
     * @return
     */
    @Query(value = "select b from BookingWarehousingEntity b where b.tradeNo = :tradeNo")
    BookingWarehousingEntity findByTradeNo(String tradeNo);

    /**
     * 根据车主的身份证号 查询车主的预约记录
     * @param idNumber
     * @return
     */
    @Query(value = "select b from BookingWarehousingEntity b where b.idNumber = :idNumber and b.status = :status")
    List<BookingWarehousingEntity> findAllByIdNumber(String idNumber, int status);

    /**
     * 根据车牌号 更新车辆的状态信息
     * @param status 0=>预约成功，1=>入库成功，2=>结算成功，3=>预约超时
     * @param licensePlateNumber 车辆车牌号
     * @return 更新记录
     */
    @Modifying
    @Transactional
    @Query(value = "update BookingWarehousing set Status = :status where LicensePlateNumber = :licensePlateNumber", nativeQuery = true)
    int updatePlateStatusInfo(int status, String licensePlateNumber);
}

